<?php

namespace app\wechat\controller\menu;

use Pheanstalk\Pheanstalk;
use think\Controller;
use think\Request;
use app\wechat\controller\Platform;
use think\Db;

// 客服消息相关
class Menuset extends Controller
{
    public $openPlatform;

    public function __construct()
    {
        parent::__construct();
    }

    // 循环发送菜单配置
    public function sendWechatMenu()
    {
        $id = $this->request->post('mid');
        $data = Db::table('nx_wechat_firstmenu')->where('id',$id)->find();
        $ghidarr = explode(',',$data['ghid_list']);
        $platform = new Platform();
        foreach ($ghidarr as $k=>$v){
            $appid = Db::table('nx_authorizer')->where('ghid',$v)->field('appid,refresh_token')->find();
            $gh = $platform->getGhWithToken($appid['appid'],$appid['refresh_token']);
            $buttons = json_decode($data['content'],true);
            $button = $buttons['button'];
            $res = $gh->menu->create($button);
        }
        return $res;
    }
}

